package com.test;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

import com.atguigu.utils.AsposeOfficeUtil;


public class FutureTest1 {
	public static void main(String[] args) {
        try {
        	FutureTask<String> future = new FutureTask<String>(new Task("E:/office/wdp.xlsx", "E:/office/pdf/xlsx2pdf.html")) ;
            new Thread(future).start();
        	System.out.println(future.get());
        	FutureTask<String> future2 = new FutureTask<String>(new Task(future.get(), "E:/office/pdf/xlsx2pdf.txt")) ;
        	new Thread(future2).start();
            // 阻塞，等待异步任务执行完毕-获取异步任务的返回值
            System.out.println("-------------:" + future2.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
 
    // 异步任务
    static class Task implements Callable<String> {
    	
		private String from;
    	private String to;
        // 返回异步任务的执行结果
        @Override
        public String call() throws Exception {
        	String str = from.substring(from.lastIndexOf(".")+1);
        	if(str.equals("xlsx") || str.equals("xls")) {
        		return AsposeOfficeUtil.excel(from, to);
        	}else if(str.equals("html")){
        		return AsposeOfficeUtil.word(from, to);
        	}
        	return null;
        	
             
        }
        
        public Task() {
			super();
		}
		public Task(String from, String to) {
			super();
			this.from = from;
			this.to = to;
		}
    }
 
}